package com.maple.controller.user;


import com.maple.constant.StatusConstant;
import com.maple.entity.Setmeal;
import com.maple.mapper.SetmealDishMapper;
import com.maple.result.Result;
import com.maple.service.SetmealService;
import com.maple.vo.DishItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController("userSetmealController")
@RequestMapping("/user/setmeal")
public class setmealController {

    @Autowired
    SetmealService setmealService;
    @Autowired
    RedisTemplate redisTemplate;


    @GetMapping("/list")
    @Cacheable(cacheNames = "setmealCache",key = "#categoryId")
    public Result queryByCategoryId(@RequestParam String categoryId){
        log.info("根据分类id查询所有套餐");
        Setmeal setmeal = new Setmeal();
        setmeal.setCategoryId(Long.valueOf(categoryId));
        setmeal.setStatus(StatusConstant.ENABLE);
        List<Setmeal> list = setmealService.list(setmeal);
        return Result.success(list);
    }


    @GetMapping("/dish/{id}")
    public Result queryBySetmealId(@PathVariable String id){
        log.info("根据套餐id查询包含的菜品");
        List<DishItemVO> dishItemById = setmealService.getDishItemById(Long.valueOf(id));
        return Result.success(dishItemById);
    }


}
